<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/28
  Time: 09:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <input type="hidden" name="id" id="id" value="${sessionScope.permissionUser.id}">
                            <label class="layui-form-label">当前密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="oldPassword" lay-verify="required" lay-verType="tips" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" lay-verify="pass" lay-verType="tips" autocomplete="off" id="LAY_password" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">八到十六位字母数字组合</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="repassword" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="setmypass">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>



<%@include file="../../../resources/inc/footer.jsp" %>
</body>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        form.on('submit(setmypass)',function (e) {
            userData=e.field;
            var b = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/g;
            if(b.test(userData.password)){
                if(userData.password!=userData.oldPassword){
                    if(userData.password==userData.repassword) {
            var id =$("#id").val();
            $.ajax({
                type: "get",
                url: "<%=basePath%>manager/permission/user/verify/"+id+".action",
                data:userData,
                success: function(data) {
                 if(data=="true"){
                     $.ajax({
                     type: "post",
                     url: "<%=basePath%>manager/permission/user/update.action",
                     data:userData,
                     success: function(data) {
                         layer.closeAll('loading');
                         data=JSON.parse(data);
                         if(data.success){
                             layer.msg("修改密码成功,请重新登陆..",{
                                 time:1000
                             },function(){
                                 $("#logoutid" , parent.document).click();
                             });

                            }
                         else{
                             layer.msg(data.msg);
                         }
                     }
                 });
                 }
                 else{layer.msg("初始密码错误");}
                }
            });

        }
                            else{
            layer.msg("两次密码输入不一致");
        }
            }
                     else{ layer.msg("新旧密码一致,无需修改");}
            }
                else{ layer.msg("密码必须包含数字与字母,且必须为八到十六位.");}
        })








    });
</script>


</html>
